﻿<?php
require 'cle_encrypt.php';
require 'config_bd.php';

$uname = $_REQUEST["name"];
$upass = $_REQUEST["pass"];

$sql = " SELECT language,role FROM t001_users WHERE uname=:uname " . 
	   " and AES_DECRYPT(PASSWORD ,:cle_encrypt) = :upass";
	
try {

    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$stmt = $dbh->prepare($sql);  
	$stmt->bindParam("uname", $uname);
	$stmt->bindParam("cle_encrypt", $cle_encrypt);
    $stmt->bindParam("upass", $upass);
	$stmt->execute();
	$data = $stmt->fetchAll(PDO::FETCH_OBJ);
	$dbh = null;
    echo '{"items":'. json_encode($data) .'}'; 
}
catch(PDOException $e) {
    echo '{"error":{"text":'. $e->getMessage() .'}}'; 
}
?>
